#include "include/main.h"
#include "include/my_mqtt.h"
#include "include/my_msq.h"

int main(int argc, char* argv[]){
    my_msq_init();

    //1.初始化 MQTT 客户端
    if(my_mqtt_init()!=0){
        printf("MQTT客户端 初始化失败!\n");
        exit(EXIT_FAILURE);
    }
    printf("MQTT客户端 初始化成功\n");

    //2 创建线程：处理MQTT的订阅消息
    pthread_t pid1;
    int retCode = pthread_create(&pid1,NULL,(void *) my_mqtt_sub_thread,NULL);//in my_mqtt_client.c
    if(retCode!=0){
        printf ("Create pthread(subsribe) error!\n");
        exit (1);
    }
    printf("MQTT订阅消息处理线程启动成功\n");

    //3 创建线程：发布MQTT主题，收取消息队列消息，接收订阅线程的指令
    pthread_t pid2;
    retCode = pthread_create(&pid2,NULL,(void *) my_mqtt_pub_thread,NULL);//in my_mqtt_client.c
    if(retCode!=0){
        printf ("Create pthread(publish) error!\n");
        exit (1);
    }
    printf("MQTT消息发布线程启动成功\n");

    
    //回收线程资源
    pthread_join(pid1, NULL);
    pthread_join(pid2, NULL);


    return 0;
}